Skip to content

Fall back to LEFT/BASELINE for invalid textAlign() values - #9378

Merged
davepagurek merged 3 commits into
processing:mainfrom
harshiltewari2004:fix-textalign-invalid-fallback
Nov 14, 2026
Merged

davepagurek merged 3 commits into
processing:mainfrom
harshiltewari2004:fix-textalign-invalid-fallback

Conversation

@harshiltewari2004

Copy link
Copy Markdown
Contributor

Resolves #9356

Changes

  • textAlign() now replaces unknown horizontal values with LEFT and unknown vertical values with BASELINE before saving them (src/type/textCore.js).
  • Added a default: fallback to the 2D _positionLines switch to match WEBGL (src/core/p5.Renderer2D.js).
  • Added textAlign unit tests in test/unit/type/attributes.js.

Why the fix is in textAlign() and not only in the 2D switch

While checking vertical alignment (as suggested in the issue), I found that the 2D canvas ignores invalid values and keeps the previous one:

Case 2D before WEBGL before
textAlign(LEFT, TOP) then textAlign(LEFT, LEFT) still drawn as TOP BASELINE
textAlign(RIGHT) then textAlign(TOP) canvas textAlign still right LEFT

So a default: alone would have drawn right-aligned text in the second case. Replacing bad values in textAlign() keeps p5's state, the canvas, and both renderers in sync. The default: stays as a safety net.

FES already warns for invalid values in both renderers, so that part is unchanged.

Tests

The two fallback tests fail on main and pass with this change.

@p5-bot

p5-bot Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

@perminder-17 perminder-17 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@davepagurek
davepagurek merged commit c60c735 into processing:main Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Couldn't load reviewers.

Assignees

Couldn't load assignees.